<?php
require_once('./includes/headers.inc.php');
require_once('./top.php');

$error = FALSE;

if(isset($_SESSION['msg']) && $_SESSION['msg']) {
    $error = $_SESSION['msg'];
    unset($_SESSION['msg']);
}

if(isset($_GET['location_id'])) {
    $location_id = $_GET['location_id'];
    $_SESSION['checkin']['location_id'] = $location_id;
} elseif(isset($_SESSION['checkin']['location_id'])) {
    $location_id = $_SESSION['checkin']['location_id'];
}

$routes = $routeMgr->getAll($location_id);
$route_list = array();
foreach($routes as $row) {
    $route_list[] =
        '<li><span class="colour ' . $row['colour'] . '">' .
        '<a href="/checkin.php?route_id=' . $row['id'] . '">' .
        $row['colour'] . ' ' . $row['difficulty'] . ($row['is_short'] ? ' short' : '') . '</a></span> ' . ($row['unicode'] ? '<img class="routetype ' . $row['route_type'] . '" src="/img/pixel.png">' : '') . '<br>' .
        ($row['created'] ? '<span class="route_date">' . $row['created'] . '</span>' : '&nbsp;') . ($row['name'] ? ' <span class="route_name">' . $row['name'] . '</span>' : ($row['rope'] ? ' <span class="route_name">(rope ' . $row['rope'] . ')</span>' : '')) .
        '</li>';
}

$replaces = array(
    'route_list'        => implode("\n", $route_list),
    'error'             => $msgMgr->formatMsg($error),
);
$lang = array(
    'header_pickroute'          => $langMgr->get('header_pickroute'),
    'btn_pickroute_add_route'   => $langMgr->get('btn_pickroute_add_route'),
    'btn_change_location'       => $langMgr->get('btn_change_location'),
);
$templateMgr->loadContent(basename(__FILE__, '.php'), array_merge($replaces, $lang));
?>
